<?php
class Staff extends CI_Controller{
	function __construct(){
		parent:: __construct();
		$this->load->model('staff_model');
		$this->load->model('room');
	}
	
	function index($error = NULL){
		$data['error'] = $error;
		$this->load->view('welcome', $data);
	}
	
	function login(){
		$user = $this->input->post('user');
		$pass = $this->input->post('pass');
		$staff = $this->staff_model->validate($user, $pass);
		if($staff){
			$data['staff_id'] = $staff->staff_id;
			$data['user'] = $staff->username;
			$data['password'] = $staff->password;
			$data['branch_id'] = $staff->branch_id;
			$this->session->set_userdata($data);
			echo 1;
		}
		else{
			echo 0;
		}
		
	}
	
	function reservation_list(){
		$data['page'] = "reserve";
		$data['list'] = NULL;
		$this->load->view('menu', $data);
	}
	
	function search_reservation(){
		$bid = $this->session->userdata('branch_id');
		$search = $this->input->post('search');
		$data['page'] = "reserve";
		$data['list'] = $this->room->search_reserve($search, $bid);
		$this->load->view('menu', $data);
	}
	
	function check_in(){
		$rid = $this->input->post('reserve_id');
		$sid = $this->session->userdata('staff_id');
		$info = array(
			'staff_id' => $sid,
			'reservation_id' => $rid
		);
		$this->room->insert_checkin($info);
	}
	
	function checkin_list(){
		$data['page'] = "checkin";
		$data['list'] = NULL;
		$this->load->view('menu', $data);
	}
	
	function search_checkin(){
		$bid = $this->session->userdata('branch_id');
		$search = $this->input->post('search');
		$reserv_checkin = array();
		$data['page'] = "checkin";
		$data['list'] = $this->room->search_checkin($search, $bid);
		$this->load->view('menu', $data);
	}
	
	function check_out(){
		$rid = $this->input->post('reserve_id');
		$sid = $this->session->userdata('staff_id');
		$info = array(
			'staff_id' => $sid,
			'reservation_id' => $rid
		);
		$this->room->insert_checkout($info);
		$this->room->delete_checkin($info);
		//$this->room->delete_reservation($rid);
	}
	
	
}